Imports System.Windows.Forms
Imports System.Security.Cryptography

Public Class frmSecuritySet
    Private m_SecBytes() As Byte = Nothing
    Private m_SecMode As Byte = &H7
    Private m_SecModeDesc As String = ""

    Friend ReadOnly Property SecurityCode() As Byte()
        Get
            Return m_SecBytes
        End Get
    End Property
    Friend ReadOnly Property SecuityMode() As Byte
        Get
            Return m_SecMode
        End Get
    End Property
    Friend ReadOnly Property SecurityModeDesc() As String
        Get
            Return m_SecModeDesc
        End Get
    End Property
    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
        If Me.tbPassphrase.Text.Length > 0 Then
            Dim password As New PasswordDeriveBytes(tbPassphrase.Text, Nothing, "SHA384", 1000)
            m_SecBytes = password.GetBytes(16)
            m_SecMode = CType(Me.cbSecMode.SelectedItem, States.comboBoxItem).Value
            m_SecModeDesc = CType(Me.cbSecMode.SelectedItem, States.comboBoxItem).Description
            Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Else
            Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        End If

        Me.Close()
    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Private Sub frmSecuritySet_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        cbSecMode.Items.Clear()
        cbSecMode.Items.AddRange(New States.comboBoxItem() { _
            New States.comboBoxItem("Level 1: All Unlocked", &H7), _
            New States.comboBoxItem("Level 2: Flash UL Locked", &H6), _
            New States.comboBoxItem("Level 3: Flash, EEprom UL Locked", &H5), _
            New States.comboBoxItem("Level 4: Flash, EEprom UL/DL Locked", &H4), _
            New States.comboBoxItem("Level 5: All Locked", &H3), _
            New States.comboBoxItem("Level 6: All Locked", &H2), _
            New States.comboBoxItem("Level 7: All Locked", &H1), _
            New States.comboBoxItem("Level 8: All Locked", &H0)})
    End Sub
End Class
